
Promise.MyAny= function(promises){
    let count = 0
    return new Promise((resolve, reject) => {
       try {
        promises.forEach((p,index) => {
            if((typeof p === 'object' && typeof p !== null) || typeof p === 'function'){
                let then = p.then
                if(typeof then === 'function'){
                    then.call(p, value => {
                        resolve(value)
                    }, reason => {
                        count += 1
                        if(count === promises.length){
                            reject(reason)
                        }
                        
                    })
                }else{
                    count += 1
                }
            }else{
                count += 1
            }
        });
       } catch (error) {
           reject(error)
       }
   })
   
}

const p1 = new Promise((resolve, reject) => {
    reject(111)
})
const p2 = new Promise((resolve, reject) => {
    setTimeout(() => {
        reject(222)
    }, 1000)
})
const p3 = function fun(){
    return 333
}
Promise.MyAny([p1, p2, p3]).then((value)=>{
    console.log("手写输出", value)
}).catch((reason) => {
    console.log("手写输出catch" , reason)
})

// Promise.any([p1, p2, p3]).then((value)=>{
//     console.log("原生输出",value)
// }).catch((reason) => {
//     console.log("手写输出catch" , reason)
// })


